<?php

namespace app\service\article;

use app\service\base\BaseModel;
use think\facade\Db;

class ArticleModel extends BaseModel
{
    protected $name = 'article';

    public function getAll($arrWhere, $field, $limit)
    {
        return Db::name($this->name)
            ->alias('A')
            ->field($field)
            ->leftJoin('article_category AC', 'A.id = AC.article_id')
            ->where($arrWhere)
            ->group('A.id')
            ->paginate($limit)
            ->toArray();
    }

    public function add($arrData)
    {
        return Db::name($this->name)->insertGetId($arrData);
    }

    public function edit($id, $arrData)
    {
        return Db::name($this->name)->where('id', $id)->update($arrData);
    }

    public function getRow($arrWhere)
    {
        return Db::name($this->name)->where($arrWhere)->find();
    }

    public function delById($id)
    {
        return Db::name($this->name)->where('id', $id)->delete();
    }
}